package com.rudolphliu.dao;

import com.rudolphliu.entity.Users;
import java.util.Date;
import org.apache.ibatis.annotations.Arg;
import org.apache.ibatis.annotations.ConstructorArgs;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface UsersMapper {
    @Delete({
        "delete from users",
        "where uid = #{uid,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String uid);

    @Insert({
        "insert into users (uid, name_title, ",
        "name_first, name_last, ",
        "email, username, ",
        "password, phone, ",
        "picture_large, picture_medium, ",
        "picture_thumbnail, nat, ",
        "create_time)",
        "values (#{uid,jdbcType=VARCHAR}, #{nameTitle,jdbcType=VARCHAR}, ",
        "#{nameFirst,jdbcType=VARCHAR}, #{nameLast,jdbcType=VARCHAR}, ",
        "#{email,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, ",
        "#{pictureLarge,jdbcType=VARCHAR}, #{pictureMedium,jdbcType=VARCHAR}, ",
        "#{pictureThumbnail,jdbcType=VARCHAR}, #{nat,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(Users record);

    @InsertProvider(type=UsersSqlProvider.class, method="insertSelective")
    int insertSelective(Users record);

    @Select({
        "select",
        "uid, name_title, name_first, name_last, email, username, password, phone, picture_large, ",
        "picture_medium, picture_thumbnail, nat, create_time",
        "from users",
        "where uid = #{uid,jdbcType=VARCHAR}"
    })
    @ConstructorArgs({
        @Arg(column="uid", javaType=String.class, jdbcType=JdbcType.VARCHAR, id=true),
        @Arg(column="name_title", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="name_first", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="name_last", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="email", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="username", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="password", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="phone", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="picture_large", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="picture_medium", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="picture_thumbnail", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="nat", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="create_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP)
    })
    Users selectByPrimaryKey(String uid);

    @UpdateProvider(type=UsersSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Users record);

    @Update({
        "update users",
        "set name_title = #{nameTitle,jdbcType=VARCHAR},",
          "name_first = #{nameFirst,jdbcType=VARCHAR},",
          "name_last = #{nameLast,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "username = #{username,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "phone = #{phone,jdbcType=VARCHAR},",
          "picture_large = #{pictureLarge,jdbcType=VARCHAR},",
          "picture_medium = #{pictureMedium,jdbcType=VARCHAR},",
          "picture_thumbnail = #{pictureThumbnail,jdbcType=VARCHAR},",
          "nat = #{nat,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where uid = #{uid,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Users record);
}